package top.huhuiyu.springboot2.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.huhuiyu.springboot2.dao.TbNewsMapper;
import top.huhuiyu.springboot2.entity.BaseResult;
import top.huhuiyu.springboot2.entity.NewsQuery;
import top.huhuiyu.springboot2.entity.TbNews;

import java.util.List;

@RestController
public class IndexController {
  @Autowired
  private TbNewsMapper tbNewsMapper;

  @RequestMapping("")
  public String index() {
    return "欢迎使用黑暗骑士的springboot服务";
  }

  @RequestMapping("/test")
  public String test(String name) {
    return "欢迎：" + name;
  }

  @RequestMapping("/test/entity")
  public BaseResult entity(String message) {
    BaseResult result = new BaseResult();

    if (StringUtils.hasText(message)) {
      result.setSuccess(true);
      result.setCode(200);
      result.setMessage(message);
    } else {
      result.setSuccess(false);
      result.setCode(500);
      result.setMessage("没有递交message参数");
    }


    return result;
  }


  // http://127.0.0.1:10000/test/queryAll
  @RequestMapping("/test/queryAll")
  public List<TbNews> queryAll() {
    return tbNewsMapper.queryAll(new NewsQuery());
  }

}
